home *** CD-ROM | disk | FTP | other *** search
/ PC Active 2009 July/August / PC Active NR.227.iso / intface / scripts / popups.js < prev    next >
Encoding:
JavaScript  |  2008-01-31  |  4.8 KB  |  157 lines

  1. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  ALTTXT V1.2
  4. //  BY: BRIAN GOSSELIN OF SCRIPTASYLUM.COM
  5. //  ADDED FADING EFFECT FOR IE4+ AND NS6+ ONLY AND OPTIMIZED THE CODE A BIT.
  6. //  SCRIPT FEATURED ON DYNAMIC DRIVE (http://www.dynamicdrive.com)
  7. //  Modifed by DD for doctype bug on Nov 13th, 2003
  8.  
  9.  
  10. var dofade=true;     // ENABLES FADE-IN EFFECT FOR IE4+ AND NS6 ONLY
  11. var center=false;     // CENTERS THE BOX UNER THE MOUSE, OTHERWISE DISPLAYS BOX TO THE RIGHT OF THE MOUSE
  12. var centertext=false; // CENTERS THE TEXT INSIDE THE BOX. YOU CAN'T SIMPLY DO THIS VIA STYLE BECAUSE OF NS4.
  13.                      // OTHERWISE, TEXT IS LEFT-JUSTIFIED. 
  14.  
  15.  
  16. ////////////////////////////// NO NEED TO EDIT BEYOND THIS POINT //////////////////////////////////////
  17.  
  18. function ietruebody(){
  19. return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
  20. }
  21.  
  22. var NS4 = (navigator.appName.indexOf("Netscape")>=0 && !document.getElementById)? true : false;
  23. var IE4 = (document.all && !document.getElementById)? true : false;
  24. var IE5 = (document.getElementById && document.all)? true : false;
  25. var NS6 = (document.getElementById && navigator.appName.indexOf("Netscape")>=0 )? true: false;
  26. var W3C = (document.getElementById)? true : false;
  27. var w_y, w_x, navtxt, boxheight, boxwidth;
  28. var ishover=false;
  29. var isloaded=false;
  30. var ieop=0;
  31. var op_id=0;
  32.  
  33. function getwindowdims(){
  34. w_y=(NS4||NS6||window.opera)? window.innerHeight : (IE5||IE4)? document.body.clientHeight : 0;
  35. w_x=(NS4||NS6||window.opera)? window.innerWidth : (IE5||IE4)? document.body.clientWidth : 0;
  36. }
  37.  
  38. function getboxwidth(){
  39. if(NS4)boxwidth=(navtxt.document.width)? navtxt.document.width : navtxt.clip.width;
  40. if(IE5||IE4)boxwidth=(navtxt.style.pixelWidth)? navtxt.style.pixelWidth : navtxt.offsetWidth;
  41. if(NS6)boxwidth=(navtxt.style.width)? parseInt(navtxt.style.width) : parseInt(navtxt.offsetWidth);
  42. }
  43.  
  44. function getboxheight(){
  45. if(NS4)boxheight=(navtxt.document.height)? navtxt.document.height : navtxt.clip.height;
  46. if(IE4||IE5)boxheight=(navtxt.style.pixelHeight)? navtxt.style.pixelHeight : navtxt.offsetHeight;
  47. if(NS6)boxheight=parseInt(navtxt.offsetHeight);
  48.  
  49. }
  50.  
  51. function movenavtxt(x,y){
  52. if(NS4)navtxt.moveTo(x,y);
  53. if(W3C||IE4){
  54. navtxt.style.left=x+'px';
  55. navtxt.style.top=y+'px';
  56. }}
  57.  
  58. function getpagescrolly(){
  59. if(NS4||NS6)return window.pageYOffset;
  60. if(IE5||IE4)return ietruebody().scrollTop;
  61. }
  62.  
  63. function getpagescrollx(){
  64. if(NS4||NS6)return window.pageXOffset;
  65. if(IE5||IE4)return ietruebody().scrollLeft;
  66. }
  67.  
  68. function writeindiv(text){
  69. if(NS4){
  70. navtxt.document.open();
  71. navtxt.document.write(text);
  72. navtxt.document.close();
  73. }
  74. if(W3C||IE4)navtxt.innerHTML=text;
  75. }
  76.  
  77. //**** END UTILITY FUNCTIONS ****//
  78.  
  79. function writetxt(text){
  80. if(isloaded){
  81. if(text!=0){
  82. ishover=true;
  83. if(NS4)text='<div class="navtext">'+((centertext)?'<center>':'')+text+((centertext)?'</center>':'')+'</div>';
  84. writeindiv(text);
  85. getboxheight();
  86. if((W3C || IE4) && dofade){
  87. ieop=0;
  88. incropacity();
  89. }}else{
  90. if(NS4)navtxt.visibility="hide";
  91. if(IE4||W3C){
  92. if(dofade)clearTimeout(op_id);
  93. navtxt.style.visibility="hidden";
  94. }
  95. writeindiv('');
  96. ishover=false;
  97. }}}
  98.  
  99. function incropacity(){
  100. if(ieop<=100){
  101. ieop+=7;
  102. if(IE4 || IE5)navtxt.style.filter="alpha(opacity="+ieop+")";
  103. if(NS6)navtxt.style.MozOpacity=ieop/100;
  104. op_id=setTimeout('incropacity()', 50);
  105. }}
  106.  
  107. function moveobj(evt){
  108. if(isloaded && ishover){
  109. margin=(IE4||IE5)? 1 : 23;
  110. if(NS6)if(document.height+27-window.innerHeight<0)margin=15;
  111. if(NS4)if(document.height-window.innerHeight<0)margin=10;
  112. //mx=(NS4||NS6)? evt.pageX : (IE5||IE4)? event.clientX : 0;
  113. //my=(NS4||NS6)? evt.pageY : (IE5||IE4)? event.clientY : 0;
  114. if (NS4){
  115. mx=evt.pageX
  116. my=evt.pageY
  117. }
  118. else if (NS6){
  119. mx=evt.clientX
  120. my=evt.clientY
  121. }
  122. else if (IE5){
  123. mx=event.clientX
  124. my=event.clientY
  125. }
  126. else if (IE4){
  127. mx=0
  128. my=0
  129. }
  130.  
  131. if(NS4){
  132. mx-=getpagescrollx();
  133. my-=getpagescrolly();
  134. }
  135. xoff=(center)? mx-boxwidth/2 : mx+5;
  136. yoff=(my+boxheight+30-getpagescrolly()+margin>=w_y)? -15-boxheight: 30;
  137. movenavtxt( Math.min(w_x-boxwidth-margin , Math.max(2,xoff))+getpagescrollx() , my+yoff+getpagescrolly());
  138. if(NS4)navtxt.visibility="show";
  139. if(W3C||IE4)navtxt.style.visibility="visible";
  140. }}
  141.  
  142. if(NS4)document.captureEvents(Event.MOUSEMOVE);
  143. document.onmousemove=moveobj;
  144. window.onload=function(){
  145.   navtxt=(NS4)? document.layers['navtxt'] : (IE4)? document.all['navtxt'] : (W3C)? document.getElementById('navtxt') : null;
  146.   getboxwidth();
  147.   getboxheight();
  148.   getwindowdims();
  149.   isloaded=true;
  150.   if((W3C || IE4) && centertext)navtxt.style.textAlign="center";
  151.   if(W3C)navtxt.style.padding='4px';
  152.   if(IE4 || IE5 && dofade)navtxt.style.filter="alpha(opacity=0)";
  153.   }
  154. window.onresize=getwindowdims;
  155.  
  156.  
  157.